package tk.hongbo.rainbow.core;


import java.util.ArrayList;

/**
 * Created by HongboZhao 2021/10/10.
 */
public class Sort {
    public String bubbleSort() {
        int[] numbers = {2, 4, 5, 2, 1};
        int temp = 0;
        for (int i = 0; i < numbers.length - 1; i++) {
            for (int j = 0; j < numbers.length - 1 - i; j++) {
                if (numbers[j] > numbers[j + 1]) {
                    temp = numbers[j];
                    numbers[j] = numbers[j + 1];
                    numbers[j + 1] = temp;
                }
            }
        }
        return numbers.toString();
    }

    //找出异常数字
    public int findStrangeNum(int[] numbers) {
        ArrayList data = new ArrayList<>();
        for (int i = 0; i < numbers.length; i++) {
            if (numbers[i] < 1 || numbers[i] > numbers.length - 1 || data.contains(numbers[i])) {
                return numbers[i];
            }
            data.add(numbers[i]);
        }
        return -1;
    }
}
